var app = getApp();
const util = require('../../../utils/util')
    //Page Object
Page({
    data: {
        systemInfo: app.systemInfo,
        pageType: true, //true=图文，false=视频
        imageList: [
            { 'id': '1', 'src': '../../../image/1.png' },
            { 'id': '1', 'src': '../../../image/1.png' },
            { 'id': '1', 'src': '../../../image/1.png' },
            { 'id': '1', 'src': '../../../image/1.png' }
        ],
        usertype: false, //false=普通会员,true=VIP会员
        workInfo: {}
    },
    getList(exchangeId) {
        let _self = this
        util.postRequest('FinanceManage/rest/exchangeDetail.do', { openId: app.openId, exchangeId: exchangeId }, function(res) {
            console.log(res)
            _self.setData({
                workInfo: res.bean
            })
        })
    },
    gotoBm(e) {
        console.log(e)
        let _self = this
        console.log(_self.data.workInfo)
        let workinfo = _self.data.workInfo.content_name
        if (workinfo.indexOf('会员') != -1) {
            let data = {
                source: 3,
                exchangeId: e.currentTarget.dataset.id,
                openId: app.openId
            }
            util.postRequest('FinanceManage/rest/exchange.do', data, function(res) {
                console.log(res)
                if (res.errorcode == 1) {
                    util.alertmodel('积分兑换提示', '兑换成功')
                } else {
                    util.alertmodel('积分兑换提示', res.message)
                }
            })
        } else if (workinfo.indexOf('课') != -1) {
            console.log("asdfasdfasdf")
            wx.navigateTo({
                url: '/packageA/pages/IntegralCourseForm/index?id=' + _self.data.workInfo.id + '&integral_count=' + _self.data.workInfo.integral_count + '&content_name=' + _self.data.workInfo.content_name
            });
        }

    },
    //options(Object)
    onLoad: function(options) {
        console.log(options.id)
        this.getList(options.id)
            // if (!this.data.usertype) {
            //     wx.showModal({
            //         title: '会员提示',
            //         content: '您还不是会员,点击确认开通会员',
            //         success(res) {
            //             if (res.confirm) {
            //                 console.log('用户点击确定')

        //                 wx.redirectTo({
        //                     url: '/packageA/pages/purchaseVip/index'
        //                 });
        //             } else if (res.cancel) {
        //                 console.log('用户点击取消')
        //                 wx.navigateBack();
        //             }
        //         }
        //     })
        // }
    },
    onReady: function() {

    },
    onShow: function() {

    },
    onHide: function() {

    },
    onUnload: function() {

    },
    onPullDownRefresh: function() {

    },
    onReachBottom: function() {

    },
    onShareAppMessage: function() {

    },
    onPageScroll: function() {

    },
    //item(index,pagePath,text)
    onTabItemTap: function(item) {

    }
});